#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=60,MAXM=2010,INF=0x3f3f3f3f;
int n,m,head[MAXN],cnt,tot,ind[MAXN],force[MAXN],limit[MAXN],price[MAXN],f[MAXN][110][MAXM],g[MAXN][MAXM],h[MAXN][MAXM];
struct edge
{
	int v,next,val;
}e[MAXN*MAXN];
void addedge(int x,int y,int z)
{
	e[++cnt]=(edge){y,head[x],z};
	head[x]=cnt;
	return;
}
void dfs(int u)
{
	if(!head[u])
	{
		limit[u]=min(limit[u],m/price[u]);
		for(int i=0;i<=limit[u];++i)
			for(int j=i;j<=limit[u];++j)
				f[u][i][j*price[u]]=(j-i)*force[u];
		return;
	}
	limit[u]=INF;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		dfs(v);
		limit[u]=min(limit[u],limit[v]/e[i].val);
		price[u]+=price[v]*e[i].val;
	}
	memset(g,-0x3f3f3f3f,sizeof(g));
	g[0][0]=0;
	limit[u]=min(limit[u],m/price[u]);
	for(int lim=limit[u];~lim;--lim)
	{
		tot=0;
		for(int i=head[u];i;i=e[i].next)
		{
			int v=e[i].v;
			++tot;
			for(int j=0;j<=m;++j)
				for(int k=0;k<=j;++k)
					g[tot][j]=max(g[tot][j],g[tot-1][j-k]+f[v][lim*e[i].val][k]);
		}
		for(int i=0;i<=lim;++i)
			for(int j=0;j<=m;++j)
				f[u][i][j]=max(f[u][i][j],g[tot][j]+force[u]*(lim-i));
	}
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;++i)
	{
		force[i]=read();
		char tmp[3];
		scanf("%s",tmp);
		if(tmp[0]=='A')
		{
			int k=read();
			while(k--)
			{
				int y=read(),z=read();
				addedge(i,y,z);
				++ind[y];
			}
		}
		else price[i]=read(),limit[i]=read();
	}
	memset(f,-0x3f3f3f3f,sizeof(f));
	cnt=0;
	for(int u=1;u<=n;++u)
	{
		if(ind[u])continue;
		dfs(u);
		++cnt;
		for(int i=0;i<=m;++i)
			for(int j=0;j<=i;++j)
				for(int k=0;k<=limit[u];++k)
					h[cnt][i]=max(h[cnt][i],h[cnt-1][j]+f[u][k][i-j]);
	}
	int ans=0;
	for(int i=0;i<=m;++i)
		ans=max(ans,h[cnt][i]);
	printf("%d\n",ans);
	return 0;
}
